package org.meeting.radish.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.meeting.radish.entity.AnswerKey;
import org.meeting.radish.mapper.AnswerKeyMapper;
import org.meeting.radish.service.AnswerKeyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class AnswerKeyServiceImpl implements AnswerKeyService {

    @Resource
    AnswerKeyMapper answerKeyMapper;

    @Override
    public Integer deleteAnswerKey(AnswerKey answerKey) {
        return answerKeyMapper.deleteAnswerKey(answerKey);
    }

    @Override
    public Integer changeAnswerKey(AnswerKey answerKey) {
        AnswerKey answer = queryAnswerKeyByUidQid(answerKey.getUid(), answerKey.getQid());
        if (answer == null) {
            return answerKeyMapper.addAnswerKey(answerKey);
        } else {
            return answerKeyMapper.updateAnswerKey(answerKey);
        }
    }

    @Override
    public AnswerKey queryAnswerKeyByUidQid(Integer uid, Integer qid) {
        return answerKeyMapper.queryAnswerKeyByUidQid(uid, qid);
    }

    @Override
    public List<AnswerKey> queryAllAnswerKeyByUid(Integer uid) {
        return answerKeyMapper.queryAllAnswerKeyByUid(uid);
    }

    @Override
    public List<AnswerKey> queryAllAnswerKeyByQid(Integer qid) {
        return answerKeyMapper.queryAllAnswerKeyByQid(qid);
    }
}
